package com.czd.support.service;

import com.czd.base.model.Paginate;
import com.czd.base.service.BaseService;
import com.czd.support.common.Configuration;
import com.czd.support.model.Links;
import org.springframework.stereotype.Service;

/**
 * 功能说明：友情链接Service
 * 作者：liuxing(2014-12-20 23:15)
 */
@Service
public class LinksService extends BaseService<Links> {

    /**
     * 查询分页
     * @param pageNo
     * @return
     */
    public Paginate queryForPaginate(int pageNo){
        Links queryBean = new Links();
        queryBean.setPageNo(pageNo);
        queryBean.setPageSize(Configuration.getInstance().getDefault_page_size());
        return this.queryForPaginate(sqlId("queryForPaginate"), sqlId("count"), queryBean);
    }

    /**
     * 根据主键查询链接详细信息
     * @param id
     * @return
     */
    public Links findById(int id) {
        return super.selectOneById(sqlId("findById"), id);
    }

    /**
     * 新增一个友情链接配置，返回主键
     * @param name
     * @param link
     * @param tank
     * @param creator
     * @param updator
     * @return
     */
    public int insertAndReturnId(String name, String link, int tank, int creator, int updator) {
        Links insertBean = new Links();
        insertBean.setName(name);
        insertBean.setLink(link);
        insertBean.setTank(tank);
        insertBean.setCreator(creator);
        insertBean.setUpdator(updator);
        return super.insertAndReturnId(sqlId("insertAndReturnId"), insertBean);
    }

    /**
     * 新增一个友情链接配置
     * @param name
     * @param link
     * @param tank
     * @param creator
     * @param updator
     * @return
     */
    public boolean insert(String name, String link, int tank, int creator, int updator) {
        return this.insertAndReturnId(name, link, tank, creator, updator) > 0;
    }

    /**
     * 修改操作
     * @param id
     * @param name
     * @param link
     * @param tank
     * @param updator
     * @return
     */
    public boolean update(int id, String name, String link, int tank, int updator) {
        Links updateBean = new Links();
        updateBean.setId(id);
        updateBean.setName(name);
        updateBean.setLink(link);
        updateBean.setTank(tank);
        updateBean.setUpdator(updator);
        return super.update(sqlId("update"), updateBean);
    }

}
